package com.example.im.adapter;

import android.graphics.Typeface;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.example.common.utils.DisplayUtils;
import com.example.common.utils.ImgLoader;
import com.example.im.R;
import com.example.im.bean.MessageBean;
import com.tencent.imsdk.v2.V2TIMMessage;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

import static com.example.im.bean.MessageBean.LAYOUT_OTHER;
import static com.example.im.bean.MessageBean.LAYOUT_OWN;

public class ChatAdapter extends BaseMultiItemQuickAdapter<MessageBean, BaseViewHolder> {

    public ChatAdapter(@Nullable List<MessageBean> data) {
        super(data);
        addItemType(LAYOUT_OWN, R.layout.item_chat_message_own);
        addItemType(LAYOUT_OTHER, R.layout.item_chat_message_other);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder viewHolder, MessageBean messageBean) {
        ImgLoader.loadRoundImg(getContext(), messageBean.getHeadPhoto(), DisplayUtils.dpToPx(8), (ImageView) viewHolder.getView(R.id.iv_photo));
        ((TextView) viewHolder.getView(R.id.tv_message)).setTypeface(Typeface.DEFAULT_BOLD);
        switch (messageBean.getMessageType()) {
            case V2TIMMessage.V2TIM_ELEM_TYPE_TEXT:
                viewHolder.setText(R.id.tv_message, messageBean.getTextMessage());
                break;
            case V2TIMMessage.V2TIM_ELEM_TYPE_CUSTOM:

                break;
        }

    }
}
